<?php
// A list of permitted file extensions
$allowed = array('png', 'jpg', 'gif','');
require_once('../../../../config.php');

if(isset($_FILES['upl']) && $_FILES['upl']['error'] == 0 ){

    $extension = pathinfo($_FILES['upl']['name'], PATHINFO_EXTENSION);
    if(!in_array(strtolower($extension), $allowed)){
        echo '{"status":"error"}';
        exit;
    }
	//$fextension = end(explode(".", basename($_FILES['upl']['name']))); ////
    $img_name = time().".".$extension;
    $thumb = "thumb-".$img_name;
	$upload = new CFile();
	if($upload->upload('upl',"../uploads/". $img_name)){
		$img = new Image("../uploads/".$img_name);
		//$img->resize("../uploads/".$thumb,150,150);
		$dim = $img->getImageD();
		$params['width'] = 1000;
		$params['height'] = 700;
		$params['destination'] = "../uploads/".$thumb;
		$i_name = $_FILES['upl']['name'];
		$i_w = $dim['W'];
		$i_h = $dim['H'];
		$i_size = ceil($_FILES['upl']['size']/1024);
		//$img->name = $params['destination'];
		//$img->imageFilteration(5,$params);
		$img_info = <<<IMG
			<fieldset dir="rtl">
				<legend>بيانات الصورة </legend>
				<label>الاسم: </label><span> $i_name</span> <br/>
				<label>الأبعاد: </label><span> $i_w  $i_h </span><br/>
				<label>الحجم (KB): </label><span> $i_size </span>
			</fieldset>
			<div id='irc_mimg'>
			<img src='./uploads/$img_name'  id='irc_mi' width='600' height='350' />
			</div>
			<input type='hidden' id='IMG_name' value='$img_name' />
IMG;
		$image_info = "['$i_name' ,'$i_w','$i_h','$i_size','$img_name'];";

		echo $image_info;
	}
} else if(isset($_REQUEST['submitForm'])){
		if($_REQUEST['submitForm'] == "IMG_EFFECTS"){
			$img = new Image("../uploads/".$_REQUEST['IMG_name']);
			//$img->resize("../uploads/".$thumb,150,150);
			$thumb = $_REQUEST['IMG_effect']."-".$_REQUEST['IMG_name'];
			$params['width'] = 1000;
			$params['height'] = 700;
			$params['destination'] = "../uploads/".$thumb;
			//$img->name = $params['destination'];
			$img->imageFilteration($_REQUEST['IMG_effect'],$params);
			$data[] = "<img src='./uploads/$thumb'  id='irc_mi' width='600' height='350' />";
			echo json_encode($data);
		}
	    
}
exit;